package com.mvc.controller;

import com.mvc.model.ItemModel;
import com.mvc.model.JsonUtil;
import com.mvc.model.Result;
import com.mvc.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @ProjectName: dior
 * @Package: com.mvc.controller
 * @ClassName: ItemController
 * @Description: 商品详情(添加)
 * @Author: lenovo
 * @Date: 2021/12/16 21:48
 * @Version: 1.0
 **/
@Controller
@RequestMapping(value = "/item/", produces = "text/html;charset=UTF-8")
public class ItemController {
    @Autowired
    ItemService itemService;


    /**
     * 商品添加
     * @param itemModel 添加的参数体
     * @return 添加状态，JSON格式
     */
    @RequestMapping(value = "add.do")
    @ResponseBody
    @Transactional
    public String itemAdd(@RequestBody ItemModel itemModel) {
        Integer row=itemService.itemAdd(itemModel);
        Result result=new Result();
        if (row!=null){
            result.setCode(0);
            result.setMsg("添加成功");
        }else {
            result.setCode(1000);
            result.setMsg("添加失败");
        }
        return JsonUtil.stringify(result);
    }
}
